package com.cloud.salon.client.authority.repository;

import com.cloud.salon.common.base.entity.authority.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Description 角色仓库接口
 * @Author wolf--LZH
 * @CreateDate 2019/4/10 0010 下午 1:30
 */
public interface RoleRepository extends JpaRepository<Role, Integer> {

    List<Role> findByIdIn(List<Integer> ids);

    @Query(value = "SELECT r.* FROM user_role ur "
            + "JOIN role r ON r.id = ur.role_id "
            + "WHERE ur.user_id = ?1", nativeQuery = true)
    List<Role> findByUser(Integer userId);

    @Query(value = "SELECT r.* FROM role_authority ra "
            + "JOIN role r ON r.id = ra.role_id "
            + "WHERE ra.authority_id = ?1", nativeQuery = true)
    List<Role> findByAuthority(Integer authorityId);
}